package com.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.media.po.MediaProcess;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ling
 */
@Mapper
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {

    /**
     *
     * @param shardIndex 分片序号
     * @param shardTotal 分片总数
     * @param count 查询的分片任务数
     */
    @Select("select * from media_process where id % #{shardTotal} = #{shardIndex} and (status='1' or status = '3') and fail_count < 3 limit #{count}")
    List<MediaProcess> selectTranscodingList(@Param("shardIndex") int shardIndex, @Param("shardTotal") int shardTotal, @Param("count") int count);

    /**
     * 开启任务，实现分布式锁
     * @param processId
     * @param errormsg
     * @return
     */
    @Update("update media_process set status = '4' where id = #{id} and (status = '1' or status = '3')")
    int startTask(@Param("id") long id);
}
